//
//  PlayView.m
//  UI27_练习 播放按钮
//
//  Created by dllo on 16/8/19.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "PlayView.h"
#import "UIView+Frame.h"

@interface PlayView ()
@property (nonatomic, strong) UIButton *playButton;
@property (nonatomic, strong) UIButton *nextButton;
@property (nonatomic, strong) UIButton *lastButton;

@property (nonatomic, copy) void (^play)(UIButton *play);
@property (nonatomic, copy) void (^pause)(UIButton *pause);
@end

@implementation PlayView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setUp];
    }
    return self;
}

- (void)setUp {
    _playButton = [self buttonImageWithName:@"hp_player_btn_play_normal" action:@selector(play:)];
//        _nextButton = [self buttonImageWithName:@"hp_player_btn_next_normal"action:<#(SEL)#>];
//        _lastButton = [self buttonImageWithName:@"hp_player_btn_pre_normal"action:<#(SEL)#>];
}

- (void)play:(void (^)(UIButton *))play pause:(void (^)(UIButton *))pause {
    self.play = play;
    self.pause = pause;
}



- (void)play:(UIButton *)playButton {
    [playButton setImage:[UIImage imageNamed:@"hp_player_btn_pause_normal"] forState:UIControlStateNormal];
    [playButton removeTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
    [playButton addTarget:self action:@selector(pasue:) forControlEvents:UIControlEventTouchUpInside];
    self.play(playButton);
    
}

- (void)pasue:(UIButton *)pasueButton {
    [pasueButton setImage:[UIImage imageNamed:@"hp_player_btn_play_normal"] forState:UIControlStateNormal];
    [pasueButton removeTarget:self action:@selector(pasue:) forControlEvents:UIControlEventTouchUpInside];
    [pasueButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
    self.pause(pasueButton);
}


- (UIButton *)buttonImageWithName:(NSString *)imageName action:(SEL)action {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    return button;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _playButton.frame = CGRectMake(0, 0, 100, 100);
    _playButton.center = CGPointMake(self.bounds.size.width / 2, CGRectGetHeight(self.bounds) / 2);
    
//    _lastButton.yh_width = 75;
//    _lastButton.yh_height = 75;
//    _lastButton.yh_centerY = _playButton.yh_centerY;
//    _lastButton.yh_centerX = _playButton.center.x - (_lastButton.yh_width / 2 + _playButton.yh_width / 2);
//    
//    _nextButton.yh_width = 75;
//    _nextButton.yh_height = 75;
//    _nextButton.yh_centerY = _playButton.yh_centerY;
//    _nextButton.yh_centerX = _playButton.center.x + (_lastButton.yh_width / 2 + _playButton.yh_width / 2);

}







/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
